﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aribaccio;
using Aribaccio.Datum;
using BDPAutodetect.Device;
using BDPAutodetect.Hardware;

namespace BDPAutodetect.Simcore
{
    public class StorageDeviceManager
    {
        /// <summary>
        /// 配置设备文件名称
        /// </summary>
        protected const string CONFIG_DEVICE_NAME = @"Config\Devicecfg.xml";
        /// <summary>
        /// 存储文件实例
        /// </summary>
        protected StorageXmlFile StorageFile { get; set; }
        /// <summary>
        /// 设备集参数管理
        /// </summary>
        protected DeviceParaManager DeviceParaMgr { get; set; }
        /// <summary>
        /// 配置设备全路径名称
        /// </summary>
        public string DevicePathName => PathHelper.GetPathFullFileName(CONFIG_DEVICE_NAME);
        /// <summary>
        /// 名称
        /// </summary>
        public string Name => StorageFile.Name;

        /// <summary>
        /// 构造函数[注入]
        /// </summary>
        public StorageDeviceManager(DeviceParaManager argDeviceParaManager)
        {
            this.StorageFile = new StorageXmlFile("菜单存储管理中心");
            this.DeviceParaMgr = argDeviceParaManager;
        }

        /// <summary>
        /// 初始化
        /// </summary>
        public void Initialize()
        {
            //获取存储通道数据对象
            var result = this.StorageFile.XMLReadStreamData<ReturnData>(this.DevicePathName);
            if (result.ResultState && result.Data != null)
            {
                //存储通道和配置表
                this.DeviceParaMgr.Initialize(result.Data);
                this.DeviceParaMgr.OpenDeviceAll();
            }
        }
    }
}
